<template>
  <div class="login-container">
    <el-form label-position="left" label-width="0px" class="demo-ruleForm login-page">
      <h3 class="title" style="margin-left:80px ">创建一个普通用户账号</h3>
      <el-form-item prop="telphone">
        <el-input type="text" v-model="form.telphone" auto-complete="off" placeholder="手机号/工号"></el-input>
      </el-form-item>
      <el-form-item prop="username">
        <el-input type="text" v-model="form.username" auto-complete="off" placeholder="用户名"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password" v-model="form.password" auto-complete="off" placeholder="密码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-radio  v-model="utype" label="0">I accept Terms and Conditions</el-radio>
      </el-form-item>
      <el-form-item style="width:100%;">
        <el-button type="primary" style="width:100%;" @click="register">注册</el-button>
        <el-link type="primary" href="/login" style="margin-left:135px ">已有账号？</el-link>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      // logining: false,
      form: {
        telphone: "",
        username: "",
        password: ""
      },
      utype:''
    }
  },
  methods: {
    register() {
       this.$http.post("user/register", this.form).then(result => {
        console.log(this.form);
        if (result.data.flag==true) {
          this.$message.success(result.body.message);
          //成功跳转路径
          this.$router.push("/login");
        } else {
          // 弹出通知框提示登录失败信息
          this.$message.error(result.body.message);
        }
      }); 
      /* let json_data = JSON.stringify(this.form)
      console.log(json_data);
      axios.post(`http://101.34.90.138:8080/ky/api/user/register`,json_data, {
                headers: { "Content-Type" : "application/json" }}).then(result => {
        console.log(result);}); */
    }
  }
};
</script>

<style>
.login-container {
  width: 100%;
  height: 100%;
}
.login-page {
  -webkit-border-radius: 5px;
  border-radius: 5px;
  margin: 180px auto;
  width: 350px;
  padding: 35px 35px 15px;
  background: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
}
label.el-checkbox.rememberme {
  margin: 0px 0px 15px;
  text-align: left;
}
</style>